from time import time
import sys
sys.path.insert(0,'../..')
from rmpoly import *

print sys.argv,

def bench1():
  R.<x> = QQ[[]]
  h = 100
  p = (1 + x + O(x^h))^-1
  rp,y = mrgens('y',8,R)
  p1 = p + p^2*y
  #print 'p1=',p1
  t1 = time()
  p2 = p1.pow_trunc(-4,'y',h)
  t2 = time()
  assert p2.mul_trunc((1+x+y)^4,'y',h) == (1+x)^8 
  print 't=%.2f' %(t2-t1)

def bench2():
  R.<x> = QQ[[]]
  h = 100
  p = (1 + x + O(x^h))^-1
  S = PowerSeriesRing(R,'y')
  y = S.gens()[0]
  p1 = p + p^2*y + O(y^h)
  t1 = time()
  p2 = p1^-4
  t2 = time()
  assert p2*(1+x+y)^4 == (1+x)^8
  print 't=%.2f' %(t2-t1)

bench1()

